<?php
 /**
 * @package		Joomla.Site
 * @subpackage	com_contact
 * @copyright	Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
 * @license		GNU General Public License version 2 or later; see LICENSE.txt
 */

defined('_JEXEC') or die;

$cparams = JComponentHelper::getParams ('com_media');
$app = JFactory::getApplication();
$template = JURI::base() . 'templates/' . $app->getTemplate();
$success = JRequest::getVar('success',0);                  	       
$input_name = JText::_('COM_CONTACT_CONTACT_WRONG_NAME');
$input_email = JText::_('COM_CONTACT_CONTACT_WRONG_EMAIL');
$input_subject = JText::_('COM_CONTACT_CONTACT_WRONG_SUBJECT');
$input_purpose = JText::_('COM_CONTACT_CONTACT_WRONG_PURPOSE');
$input_message = JText::_('COM_CONTACT_CONTACT_WRONG_MESSAGE');
?>     
<style>
	.contact-miscinfo img{
		width:400px !important;
		height:310px !important;
	}
</style>             
 <script type="text/javascript">                   
jQuery(document).ready(function(jQuery) {
	jQuery.validator.addMethod('postalcode', function (value) { 
		if(value=='') return true;	
		return /^\d{4}$/.test(value); 
	   }, '');
		
		
		jQuery("#contact-form").validate(
			{
				errorPlacement: function(error, element) {			
			},
			invalidHandler: function(form, validator) {
			  var errors = validator.numberOfInvalids();
			if (errors) {
                //$('#alert').html(validator['errorList'][0]['message']);
				jQuery('#alert').html(validator['errorList'][0]['message']);
    			jQuery('#backoverlay').show();
    			jQuery('#show_popup').show();
            	jQuery('#f_focus').html(validator['errorList'][0]['element'].name);
				validator['errorList'][0]['element'].focus();
				
			  } else {
			  }
			},
			rules: {
				name:{
					required: true,
				},			
				email: {
					required: true,
					email:true,
				},
				subject:{
					required: true,
				},
				purpose:{
					required: true,
				},
				message:{
					required: true,
				},
			},
			messages: {
				name: "<?php echo $input_name; ?>",
				email: "<?php echo $input_email; ?>",
				subject: "<?php echo $input_subject; ?>",
				purpose: "<?php echo $input_purpose; ?>",
				message: "<?php echo $input_message; ?>",
			}
		});
	});
</script>
<div class="contact">
<h1 class="contentTitle"><?php echo $this->contact->name; ?>	</h1>	

<div id="contact-form-cont">
	<?php if($success): ?>
	<p>Thank you for your contact. I will reply as soon as possible :)</p>
	<?php else: ?>
	<div class="contact-form">
		<form id="contact-form" name="contact-form" action="index.php" method="post" class="form-validate">
			<fieldset>
				<dl>
					<dt><label id="jform_contact_name-lbl" for="jform_contact_name" class="hasTip required" title=""><?php echo $this->form->getLabel('contact_name'); ?><span class="star">&nbsp;*</span></label></dt>
					<dd><input type="text" name="name" id="name" size="30" ></dd>
					<dt><label id="jform_contact_email-lbl" for="jform_contact_email" class="hasTip required" title=""><?php echo $this->form->getLabel('contact_email'); ?><span class="star">&nbsp;*</span></label></dt>
					<dd><input type="text" name="email" id="email" value="" size="30" ></dd>
					<dt><label id="jform_contact_emailmsg-lbl" for="jform_contact_emailmsg" class="hasTip required" title=""><?php echo $this->form->getLabel('contact_subject'); ?><span class="star">&nbsp;*</span></label></dt>
					<dd><input type="text" name="subject" id="subject" size="60" ></dd>
					<dt><label id="jform_contact_emailmsg-lbl" for="jform_contact_emailmsg" class="hasTip required" title=""><?php echo JText::_('COM_CONTACT_CONTACT_PURPOSE_LABEL'); ?><span class="star">&nbsp;*</span></label></dt>
					<dd>
						<select name="purpose" id="purpose">
							<option value=""><?php echo JText::_('COM_CONTACT_CONTACT_PURPOSE_VALUE0_LABEL'); ?></option>
							<option value="1"><?php echo JText::_('COM_CONTACT_CONTACT_PURPOSE_VALUE1_LABEL'); ?></option>
							<option value="2"><?php echo JText::_('COM_CONTACT_CONTACT_PURPOSE_VALUE2_LABEL'); ?></option>
							<option value="3"><?php echo JText::_('COM_CONTACT_CONTACT_PURPOSE_VALUE3_LABEL'); ?></option>
							<option value="4"><?php echo JText::_('COM_CONTACT_CONTACT_PURPOSE_VALUE4_LABEL'); ?></option>
							<option value="5"><?php echo JText::_('COM_CONTACT_CONTACT_PURPOSE_VALUE5_LABEL'); ?></option>
							<option value="6"><?php echo JText::_('COM_CONTACT_CONTACT_PURPOSE_VALUE6_LABEL'); ?></option>
						</select>
					</dd>
					<dt><label id="jform_contact_message-lbl" for="jform_contact_message" class="hasTip required" title=""><?php echo $this->form->getLabel('contact_message'); ?><span class="star">&nbsp;*</span></label></dt>
					<dd><textarea name="message" id="message" cols="50" rows="10" ></textarea></dd>
					<dt><label id="jform_contact_email_copy-lbl" for="jform_contact_email_copy" class="hasTip" title=""><?php echo $this->form->getLabel('contact_email_copy'); ?></label></dt>
					<dd><input type="checkbox" name="copy" id="copy" ></dd>
					<dt></dt>
					<dd>
						<button class="button validate" type="submit" onclick="jQuery('#contact-form').submit()"><?php echo JText::_('COM_CONTACT_CONTACT_SEND'); ?></button>
						<input type="hidden" name="option" value="com_contact" />
						<input type="hidden" name="task" value="contact.submit" />
						<input type="hidden" name="return" value="<?php echo $this->return_page;?>" />
						<input type="hidden" name="id" value="<?php echo $this->contact->slug; ?>" />
						<?php echo JHtml::_( 'form.token' ); ?>
					</dd>
				</dl>
			</fieldset>
		</form>
	</div>
	<?php endif; ?>
</div>
<?php echo $this->contact->misc; ?>	

<div class="clr"></div>
</div>

<?php return; ?>
<div class="contact<?php echo $this->pageclass_sfx?>">
<?php if ($this->params->get('show_page_heading')) : ?>
<h1>
	<?php echo $this->escape($this->params->get('page_heading')); ?>
</h1>
<?php endif; ?>
	<?php if ($this->contact->name && $this->params->get('show_name')) : ?>
		<h2>
			<span class="contact-name"><?php echo $this->contact->name; ?></span>
		</h2>
	<?php endif;  ?>
	<?php if ($this->params->get('show_contact_category') == 'show_no_link') : ?>
		<h3>
			<span class="contact-category"><?php echo $this->contact->category_title; ?></span>
		</h3>
	<?php endif; ?>
	<?php if ($this->params->get('show_contact_category') == 'show_with_link') : ?>
		<?php $contactLink = ContactHelperRoute::getCategoryRoute($this->contact->catid);?>
		<h3>
			<span class="contact-category"><a href="<?php echo $contactLink; ?>">
				<?php echo $this->escape($this->contact->category_title); ?></a>
			</span>
		</h3>
	<?php endif; ?>
	<?php if ($this->params->get('show_contact_list') && count($this->contacts) > 1) : ?>
		<form action="#" method="get" name="selectForm" id="selectForm">
			<?php echo JText::_('COM_CONTACT_SELECT_CONTACT'); ?>
			<?php echo JHtml::_('select.genericlist',  $this->contacts, 'id', 'class="inputbox" onchange="document.location.href = this.value"', 'link', 'name', $this->contact->link);?>
		</form>
	<?php endif; ?>
	<?php  if ($this->params->get('presentation_style')!='plain'){?>
		<?php  echo  JHtml::_($this->params->get('presentation_style').'.start', 'contact-slider'); ?>
	<?php  echo JHtml::_($this->params->get('presentation_style').'.panel', JText::_('COM_CONTACT_DETAILS'), 'basic-details'); } ?>
	<?php if ($this->params->get('presentation_style')=='plain'):?>
		<?php  echo '<h3>'. JText::_('COM_CONTACT_DETAILS').'</h3>';  ?>
	<?php endif; ?>
	<?php if ($this->contact->image && $this->params->get('show_image')) : ?>
		<div class="contact-image">
			<?php echo JHtml::_('image', $this->contact->image, JText::_('COM_CONTACT_IMAGE_DETAILS'), array('align' => 'middle')); ?>
		</div>
	<?php endif; ?>

	<?php if ($this->contact->con_position && $this->params->get('show_position')) : ?>
		<p class="contact-position"><?php echo $this->contact->con_position; ?></p>
	<?php endif; ?>

	<?php echo $this->loadTemplate('address'); ?>

	<?php if ($this->params->get('allow_vcard')) :	?>
		<?php echo JText::_('COM_CONTACT_DOWNLOAD_INFORMATION_AS');?>
			<a href="<?php echo JRoute::_('index.php?option=com_contact&amp;view=contact&amp;id='.$this->contact->id . '&amp;format=vcf'); ?>">
			<?php echo JText::_('COM_CONTACT_VCARD');?></a>
	<?php endif; ?>
	<p></p>
	<?php if ($this->params->get('show_email_form') && ($this->contact->email_to || $this->contact->user_id)) : ?>

		<?php if ($this->params->get('presentation_style')!='plain'):?>
			<?php  echo JHtml::_($this->params->get('presentation_style').'.panel', JText::_('COM_CONTACT_EMAIL_FORM'), 'display-form');  ?>
		<?php endif; ?>
		<?php if ($this->params->get('presentation_style')=='plain'):?>
			<?php  echo '<h3>'. JText::_('COM_CONTACT_EMAIL_FORM').'</h3>';  ?>
		<?php endif; ?>
		<?php  echo $this->loadTemplate('form');  ?>
	<?php endif; ?>
	<?php if ($this->params->get('show_links')) : ?>
		<?php echo $this->loadTemplate('links'); ?>
	<?php endif; ?>
	<?php if ($this->params->get('show_articles') && $this->contact->user_id && $this->contact->articles) : ?>
		<?php if ($this->params->get('presentation_style')!='plain'):?>
			<?php echo JHtml::_($this->params->get('presentation_style').'.panel', JText::_('JGLOBAL_ARTICLES'), 'display-articles'); ?>
			<?php endif; ?>
			<?php if  ($this->params->get('presentation_style')=='plain'):?>
			<?php echo '<h3>'. JText::_('JGLOBAL_ARTICLES').'</h3>'; ?>
			<?php endif; ?>
			<?php echo $this->loadTemplate('articles'); ?>
	<?php endif; ?>
	<?php if ($this->params->get('show_profile') && $this->contact->user_id && JPluginHelper::isEnabled('user', 'profile')) : ?>
		<?php if ($this->params->get('presentation_style')!='plain'):?>
			<?php echo JHtml::_($this->params->get('presentation_style').'.panel', JText::_('COM_CONTACT_PROFILE'), 'display-profile'); ?>
		<?php endif; ?>
		<?php if ($this->params->get('presentation_style')=='plain'):?>
			<?php echo '<h3>'. JText::_('COM_CONTACT_PROFILE').'</h3>'; ?>
		<?php endif; ?>
		<?php echo $this->loadTemplate('profile'); ?>
	<?php endif; ?>
	<?php if ($this->contact->misc && $this->params->get('show_misc')) : ?>
		<?php if ($this->params->get('presentation_style')!='plain'){?>
			<?php echo JHtml::_($this->params->get('presentation_style').'.panel', JText::_('COM_CONTACT_OTHER_INFORMATION'), 'display-misc');} ?>
		<?php if ($this->params->get('presentation_style')=='plain'):?>
			<?php echo '<h3>'. JText::_('COM_CONTACT_OTHER_INFORMATION').'</h3>'; ?>
		<?php endif; ?>
				<div class="contact-miscinfo">
					<div class="<?php echo $this->params->get('marker_class'); ?>">
						<?php echo $this->params->get('marker_misc'); ?>
					</div>
					<div class="contact-misc">
						<?php echo $this->contact->misc; ?>
					</div>
				</div>
	<?php endif; ?>
	<?php if ($this->params->get('presentation_style')!='plain'){?>
			<?php echo JHtml::_($this->params->get('presentation_style').'.end');} ?>
</div>
